package com.caoxw.Android.CityBus;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.widget.Toast;

public class ConfigMgr {
	private Context m_objContext;
	public String m_strDataFilePath;
	public int m_intMaxDeep = 3;
	public int m_intTimeout = 15;
	public boolean m_bolCheckVersion = true;
	private SharedPreferences m_Settings;
	private static String PREFS_NAME = "CityDataCfg";

	public ConfigMgr(Context contex) {
		m_objContext = contex;
		m_Settings = m_objContext.getSharedPreferences(PREFS_NAME,0);
		m_strDataFilePath = m_Settings.getString("DataFile", "");
		m_intMaxDeep = m_Settings.getInt("MaxDeep", 3);
		m_intTimeout = m_Settings.getInt("Timeout", 15);
		m_bolCheckVersion = m_Settings.getBoolean("CheckVersionApp",true);
	}

	public int getTimeOut() {
		return getInt("TimeOut", 15);
	}

	public int getMaxDeep() {
		return getInt("MaxDeep", 3);
	}

	public String getDataFile() {
		return getString("DataFile", "");
	}

	public void putTimeOut(int value) {
		putInt("TimeOut", value);
		m_intTimeout = value;
	}

	public void putMaxDeep(int value) {
		putInt("MaxDeep", value);
		m_intMaxDeep = value;
	}

	public void putDataFile(String value) {
		putString("DataFile", value);
		m_strDataFilePath = value;
	}

	public int getInt(String key, int defValue) {
		return m_Settings.getInt(key, defValue);
	}

	public String getString(String key, String defValue) {
		return m_Settings.getString(key, defValue);
	}

	public boolean getCheckApp(){
		return m_Settings.getBoolean("CheckVersionApp",true);
	}
	public boolean getCheckData(){
		return m_Settings.getBoolean("CheckVersionData",true);
	}
	public boolean getBoolean(String key, boolean defValue) {
		return m_Settings.getBoolean(key, defValue);
	}

	public float getFloat(String key, float defValue) {
		return m_Settings.getFloat(key, defValue);
	}

	public float getLong(String key, long defValue) {
		return m_Settings.getLong(key, defValue);
	}

	public void putInt(String key, int value) {
		SharedPreferences.Editor editor = m_Settings.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public void putString(String key, String value) {
		SharedPreferences.Editor editor = m_Settings.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public void putBoolean(String key, boolean value) {
		SharedPreferences.Editor editor = m_Settings.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public void putLong(String key, long value) {
		SharedPreferences.Editor editor = m_Settings.edit();
		editor.putLong(key, value);
		editor.commit();
	}

	public void putFloat(String key, float value) {
		SharedPreferences.Editor editor = m_Settings.edit();
		editor.putFloat(key, value);
		editor.commit();
	}


}
